package com.corx.network.core.model;

import com.corx.network.core.type.NetworkTypeEnum;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * @author gx
 * @version 1.0.0
 */
public abstract class MessageBase {

    /**
     * 业务设备ID
     */
    protected String deviceId;

    /**
     * 网络组件类型
     */
    protected NetworkTypeEnum networkType;

    /**
     * 全局唯一 ID（用于匹配响应）
     */
    protected String messageId;
    /**
     * 头部信息（可放 token、qos、自定义业务信息）
     */
    protected Map<String, String> headers;
    /**
     * 消息体，原始字节
     */
    protected byte[] payload;

    protected MessageBase() {
    }

    protected MessageBase(String deviceId, String messageId, NetworkTypeEnum networkType , byte[] payload, Map<String, String> headers) {

        this.deviceId = deviceId;
        this.messageId = messageId;
        this.networkType = networkType;
        this.payload = Objects.requireNonNull(payload, "payload cannot be null");
        this.headers = headers != null ? headers : new HashMap<>(1);
    }

    public NetworkTypeEnum getNetworkType() {
        return networkType;
    }

    public void setNetworkType(NetworkTypeEnum networkType) {
        this.networkType = networkType;
    }

    public String getDeviceId() {
        return deviceId;
    }

    public void setDeviceId(String deviceId) {
        this.deviceId = deviceId;
    }

    public String getMessageId() {
        return messageId;
    }

    public void setMessageId(String messageId) {
        this.messageId = messageId;
    }

    public Map<String, String> getHeaders() {
        return headers;
    }

    public void setHeaders(Map<String, String> headers) {
        this.headers = headers;
    }

    public byte[] getPayload() {
        return payload;
    }

    public void setPayload(byte[] payload) {
        this.payload = payload;
    }
}
